// pages/finance/result.js
import config from '../../config.js';
const base = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab_title: ["A等额本息还款", "B灵活还款"],
    currentIndex: 0,
    result: {},
    carPrice: 0,
    paymentRatio: 0,
    decoratePrice: 0,
    name: '',
    tel: ''

  },

  switchTab(e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      currentIndex: index
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var carPrice = options.carPrice;
    var paymentRatio = options.paymentRatio;
    var name = options.name;
    var decoratePrice = options.decoratePrice;
    var tel = options.tel;

    this.setData({
      carPrice: carPrice,
      paymentRatio: paymentRatio,
      decoratePrice: decoratePrice,
      name: name,
      tel: tel
    })


    this.calculateAction();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  calculateAction() {
    var that = this;
    console.log(that.data);
    wx.request({
      url: base.loanCalculate,
      method: "POST",
      header: {
        "Cookie": wx.getStorageSync("session"),
        "content-type": "application/x-www-form-urlencoded",
      },
      data: {
        name: that.data.name,
        tel: that.data.tel,
        carPrice: that.data.carPrice,
        paymentRatio: that.data.paymentRatio,
        decoratePrice: that.data.decoratePrice
      },
      success(res) {
        if (res.data.status == 200) {
            that.setData({
              result:res.data.data
            })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: "none"
          })
        }
      }
    })
  }
})